/**
 * ZixunApi.java
 * com.zhihu.zixun.api
 * Copyright (c) 2016, 北京聚智未来科技有限公司版权所有.
*/

package com.zhihu.zixun.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.zhihu.zhihuquan.model.Answer;
import com.zhihu.zixun.model.Topic;
import com.zhihu.zixun.model.ZProblem;

/**
 * 咨询列表
 *
 * @author   wxl
 * @Date	 2016年12月23日 	 
 */
public class ZixunApi extends Controller {

	/**
	 * 查询
	 * 根据分类id查列表
	 */
	public Map<String, Object> queryList() {
		String id = getPara("id");
		Map<String, Object> map = new HashMap<String, Object>();
		List<ZProblem> querylist = ZProblem.dao.queryAll(id);
		map.put("querylist", querylist);
		setAttr("ds", querylist);
		render("/eova/widget/form/gameTask.html");
		renderJson();
		return map;
	}

	/**
	 * 点击title
	 * @param id
	 */
	public Map<String, Object> queryAnswer() {
		String id = getPara("pid");
		//话题列表
		Map<String, Object> map = new HashMap<String, Object>();
		List<Topic> topicList = Topic.dao.queryTopic(id);
		//问题详情
		ZProblem problemOne = ZProblem.dao.queryProblem(id);
		//回答列表
		List<Answer> answerList = Answer.dao.queryAnswerList(id);
		//阅读量加一
		int plookNo = ZProblem.dao.updateLookNo(id);

		setAttr("ds", topicList);
		setAttr("problemOne", problemOne);
		setAttr("answerList", answerList);
		setAttr("plookNo", plookNo);
		render("/eova/widget/form/gameTask.html");
		renderJson();
		return map;
	}

	/**
	 * 点击回答
	 * @param answerid
	 */
	public void queryAnswerInfo() {
		String aid = getPara("aid");
		Answer answerInfo = Answer.dao.queryAnswer(aid);
		setAttr("ds", answerInfo);
		render("/eova/widget/form/gameTask.html");
		renderJson();
	}
}
